$authr()

require('../css/runing.less')

require('../font/iconfont.css')



document.ready(function () {


    let timeObj = {
        useTime: "",
        krololi: "",
        useDis: ""
    }

    let uset = document.querySelector('#userTime');


    let pause = document.querySelector('#pause');
    let suo = document.querySelector('#suo');


    let continueRun = document.querySelector("#continueRun");
    let endRun = document.querySelector("#endRun");


    // 时间对象
    let hourObj = document.querySelector('#hour');
    let minuteObj = document.querySelector('#minute');
    let secendObj = document.querySelector('#secend');

    // 卡路里
    let krololi = document.querySelector('#krololi')
    let kro = 0

    // 总距离
    let allDistance = document.querySelector('#AllDistance');
    let distance = 0

    // 记录时间
    let h = 0
    let m = 0
    let s = 0

    // 卡路里设置
    let kroSet = setInterval(() => {
        distance++
        kro++
        krololi.innerHTML = kro
        allDistance.innerHTML = "00." + "0" + distance
    }, 1600);



    // 跑步时间
    let runtime = null

    function runTimeMethod() {
        runtime = setInterval(() => {
            s++
            countTime(h, m, s)
            so = transAddZero(s)
            secendObj.innerHTML = so
        }, 1000);
    }
    runTimeMethod()
    // 跑步时间



    // 暂停run
    pause.addEventListener('click', function () {
        pass()
        clearInterval(runtime)
        clearInterval(kroSet)
    })

    // 继续run
    continueRun.addEventListener('click', function () {
        stop();
        runTimeMethod()
        kroSet = setInterval(() => {
            distance++
            kro++
            krololi.innerHTML = kro
            allDistance.innerHTML = distance
        }, 1600);
    })

    // 结束run
    endRun.addEventListener('click', function () {
        timeObj.krololi = kro
        timeObj.useTime = uset.innerText
        timeObj.useDis = distance

        sessionStorage.setItem('runtime', JSON.stringify(timeObj))
        location.href = `./runend.html`
    })



    // 暂停样式
    function pass() {
        suo.classList.add('none')
        pause.classList.add("none");
        continueRun.classList.remove("none")
        endRun.classList.remove("none")
    }

    // 开始样式
    function stop() {
        suo.classList.remove('none')
        pause.classList.remove("none");
        continueRun.classList.add("none")
        endRun.classList.add("none")
    }




    // 计算时间函数
    function countTime(h1, m1, s1) {

        if (s1 >= 60) {
            s = 0
            m = m1 + 1
            minuteObj.innerHTML = transAddZero(m)
        }
        if (m1 >= 60) {
            m = 0
            h += h1
            hourObj.innerHTML = transAddZero(h)
        }
        if (h >= 24) {
            h = 0
            m = 0
            s = 0
        }
    }

    // 转换补零
    function transAddZero(num) {
        return Number.parseInt(num) > 9 ? num : "0" + num
    }

})